from django.utils.safestring import mark_safe
from django.urls import reverse
from stark.service.s1 import StarkHandler, m2m_display
from app_main.forms.for_stark import ClassListModelForm
from .local_permission import LocalPermissionHandler


class ClassListHandler(LocalPermissionHandler, StarkHandler):

    def display_teach_record(self, obj=None, is_head=None, *args, **kwargs):
        if is_head:
            return '上课记录'

        re_url = reverse('stark:app_main_teachrecord_list', args=(obj.id,))
        return mark_safe('<a target="blank" href="%s">上课记录</a>' % re_url)

    list_display = [
        'school',
        'course',
        'semester',
        'start_date',
        m2m_display('授课老师', 'tech_teachers'),
        display_teach_record,
        StarkHandler.display_edit,
        StarkHandler.display_del
    ]

    model_form_class = ClassListModelForm
